package com.situ.mall.service.Impl;

import com.situ.mall.mapper.EvaluateMapper;
import com.situ.mall.mapper.OrderItemMapper;
import com.situ.mall.mapper.OrderMapper;
import com.situ.mall.pojo.entity.Evaluate;
import com.situ.mall.pojo.entity.Order;
import com.situ.mall.pojo.entity.OrderItem;
import com.situ.mall.pojo.vo.EvaluateVO;
import com.situ.mall.service.IEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EvaluateServiceImpl implements IEvaluateService {
    @Autowired
    private OrderItemMapper orderItemMapper;
    @Autowired
    private EvaluateMapper evaluateMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public void add(Evaluate evaluate, Long orderNo) {
        List<OrderItem> list = orderItemMapper.selectByOrderNo(orderNo);
        for (OrderItem orderItem : list) {
            evaluate.setProductId(orderItem.getProductId());
            evaluateMapper.insertSelective(evaluate);
        }
        Order order = new Order();
        order.setOrderNo(orderNo);
        order.setStatus(60);
        Date date = new Date();
        order.setCloseTime(date);
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public List<EvaluateVO> selectByProductId(Integer productId) {
        return evaluateMapper.selectByProductId(productId);
    }
}
